<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>保存模板</title>
    <jsp:include page="../../head.jsp"/>
</head>
<script type="text/javascript">
    var trailId = "${trail.id}";
    var declarationId = "${declare.id}";
    var type = "";
    if (trailId != "" && declarationId == "") {
        type = "C";
    } else if (trailId == "" && declarationId != "") {
        type = "D";
    }
    var formSetting = {
        title: "模板命名",
        module: 'save',
        numCount: 1,

        columns: [{
            name: "model_name",
            label: "模板名"
        }],
        form: {
            'url': 'model-checkIsExistModel?type=' + type,
            'data': null,
            'ajaxForm': {
                success: function (data) {
                    var state = $.parseJSON(data.msg).state;
                    var msg = $.parseJSON(data.msg).msg;
                    var model_name = $("input[name=model_name]").val();
                    if (state == "2") {
                        //alert(msg);
                        var r = confirm(msg);
                        if (r == true) {
                            $.ajax({
                                       type: "post",
                                       'url': 'model-save?trail.id=' + trailId + "&declare.id="
                                              + declarationId + "&model_name=" + model_name
                                              + "&isCover=1",
                                       beforeSend: function (XMLHttpRequest) {
                                       },
                                       success: function (data, textStatus) {
                                           var state = $.parseJSON(data.msg).state;
                                           var msg = $.parseJSON(data.msg).msg;
                                           alert(msg);
                                           if (state == "1") {
                                               jw.close();
                                           }
                                       },
                                       complete: function (XMLHttpRequest, textStatus) {
                                       },
                                       error: function () {
                                       }
                                   });
                        }
                    } else {
                        $.ajax({
                                   type: "post",
                                   'url': 'model-save?trail.id=' + trailId + "&declare.id="
                                          + declarationId + "&model_name=" + model_name,
                                   beforeSend: function (XMLHttpRequest) {
                                   },
                                   success: function (data, textStatus) {
                                       var state = $.parseJSON(data.msg).state;
                                       var msg = $.parseJSON(data.msg).msg;
                                       alert(msg);
                                       if (state == "1") {
                                           jw.close();
                                       }
                                   },
                                   complete: function (XMLHttpRequest, textStatus) {
                                   },
                                   error: function () {
                                   }
                               });
                    }
                }
            },
            buttons: {}
        }
        /* 	form : {
         'url' : 'model-save?trail.id='+trailId+"&declare.id="+declarationId,
         'data' : null,
         'ajaxForm' : {
         success : function(data) {
         var state = $.parseJSON(data.msg).state;
         var msg = $.parseJSON(data.msg).msg;
         alert(msg);
         if(state=="1"){
         jw.close();
         }
         }
         },
         buttons : {}
         } */
    };
    $(document).ready(function () {
        $("#formtable").mrdForm(formSetting);
    });
</script>
<body>
<div style="width: 100%">
    <div id="formtable"></div>
</div>
</body>
</html>
